<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
   <link rel="stylesheet" href="/frontSrc/lib/layui-v2.6.3/css/layui.css" media="all">

</head>
<body>


<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg-offset1" layui-col-lg6>
            <div class="layui-form layuimini-form">
                <form class="layui-form" action="" lay-filter="studentForm">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 40px;">
                        <legend>个人信息</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">单据编号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="d_id" required lay-verify="required" placeholder=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">创建时间:</label>
                        <!-- layui-input-block 输入框会占满除文字外的整行 -->
                        <div class="layui-input-block">
                            <input readonly id="birth" type="text" name="Creation_time" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">申请人：</label>
                        <div class="layui-input-block">
                            <input type="text" name="applicant" required lay-verify="required" placeholder=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属部门：</label>
                        <div class="layui-input-block">
                            <input type="text" name="subordinate_department" required lay-verify="required" placeholder=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 80px;">
                        <legend>请假申请</legend>
                    </fieldset>
                    <!--                    根据id修改学员信息，但是id 没必要让用户看到，但是需要传到后端程序-->
                    <input type="hidden" name="id" value="" class="layui-input">



                    <div class="layui-form-item">
                        <label class="layui-form-label">单行选择框</label>
                        <div class="layui-input-block">
                            <select name="t_id" lay-filter="aihao">
                                <option value="1">其他</option>
                                <option value="2" selected="">病假</option>
                                <option value="3">调休</option>
                                <option value="4">事假</option>
                                <option value="5">孕假</option>
                            </select>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">开始时间:</label>
                        <!-- layui-input-block 输入框会占满除文字外的整行 -->
                        <div class="layui-input-block">
                            <input readonly id="birth1" type="text" name="start_time" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">结束时间:</label>
                        <!-- layui-input-block 输入框会占满除文字外的整行 -->
                        <div class="layui-input-block">
                            <input readonly id="birth2" type="text"  name="end_time" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
					
					<div class="layui-form-item">
					    <label class="layui-form-label">请假天数：</label>
					    <div class="layui-input-block">
					        <input id = "daysoff" type="text" onclick="datecha()" name="days_off" required lay-verify="required" placeholder=""
					               autocomplete="off" class="layui-input">
					    </div>
					</div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">原因：</label>
                        <div class="layui-input-block">
                            <textarea name="reason_for_leave"  autocomplete="off" coplaceholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">原因：</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="reason_for_leave" required lay-verify="required" placeholder=""-->
<!--                                   autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="formDemo1">撤回</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>

<script src="/frontSrc/bs/js/jquery.min.js"></script>
<script src="/frontSrc/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(["laydate","form","upload"],function(){
        var laydate = layui.laydate;
        var upload = layui.upload;
        var form = layui.form;
         var $ = layui.jquery;
          var element = layui.element;




        //执行一个laydate实例
        laydate.render({
            elem: '#birth', //指定元素
            format:'yyyy-MM-dd',
            // value:'2012/12/12' //默认值
            value:new Date() //默认值
        });
        laydate.render({
            elem: '#birth1', //指定元素
            format:'yyyy-MM-dd',

        });
        laydate.render({
            elem: '#birth2', //指定元素
            format:'yyyy-MM-dd',
        });
		
		
		 datecha = function (){
			
			var date1 = new Date(document.getElementById("birth1").value);
			var date2 = new Date(document.getElementById("birth2").value);
			var diff = Math.abs(date1.getTime() - date2.getTime());
			var days = Math.ceil(diff / (1000 * 3600 * 24));
			
			var ad = document.getElementById("daysoff")
			ad.value = days
			
			
			// 	form.val("studentForm",{
			// 				   "days_off":days
			// 				});
			
			
			
			// var ad = document.getElementById("days_off")
			// ad.value = days
			// $.("#days_off").val("days")
		}

       d1 =  function (data){
           var user = JSON.parse(localStorage.getItem("token"))
           $.ajax({
               "url":"http://localhost:8080/api/leaveInformation/partialData",
               // "headers":{"token":token},

               "data": {applicant:user.username,subordinate_department:user.department},
               // result 参数 表式后台响应的数据
               "success":function(result){
                   if(result.code == 200){
                       var obj = result.data.res
                       form.val("studentForm",{
                           "d_id":obj.d_id,
                           "applicant":obj.applicant,
                           "subordinate_department":obj.subordinate_department,
                           // "id":obj.id,

                       });
                   }else{
                       layer.msg(result.msg);
                   }
               },
               "dataType":"json"
           });

        }

        d1();

        //监听提交
        form.on('submit(formDemo)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:"http://localhost:8080/api/leaveInformation/allDate",
                // "headers":{"token":token},
                type:"post",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                // result 参数 表式后台响应的数据
                success:function(result){
                    if(result.code == 200){

                        // 关闭 弹出层

                        parent.layer.msg("编辑成功");


                    }else{
                        layer.msg(result.message);
                    }
                },
                dataType:"json"
            });

            return false;
        });
		
		//监听提交
		form.on('submit(formDemo1)', function (data) {
		    // layer.msg(JSON.stringify(data.field));
		    $.ajax({
		        url:"http://localhost:8080/api/leaveInformation/deleteDate",
		        // "headers":{"token":token},
		        type:"post",
		        contentType:"application/json",
		        data:JSON.stringify(data.field),
		        // result 参数 表式后台响应的数据
		        success:function(result){
		            if(result.code == 200){
		
		                // 关闭 弹出层
		
		                parent.layer.msg(result.message,{time:1000,
		                end:function(){
		                	
		                	location.reload();
		                }});
						
		
		            }else{
		                layer.msg(result.message);
		            }
		        },
		        dataType:"json"
		    });
		
		    return false;
		});

    });
	
	
</script>
</body>
</html>